package com.wiscamp.ninechapters.problems.application.assemblers;

import com.wiscamp.ninechapters.problems.application.dto.vo.problems.AnswerVO;
import com.wiscamp.ninechapters.problems.application.dto.vo.problems.OptionVO;
import com.wiscamp.ninechapters.problems.application.dto.vo.problems.QuestionVO;
import com.wiscamp.ninechapters.problems.application.dto.vo.problems.StemVO;
import com.wiscamp.ninechapters.problems.domain.models.problems.answers.Answer;
import com.wiscamp.ninechapters.problems.domain.models.problems.problems.Stem;
import com.wiscamp.ninechapters.problems.domain.models.problems.questions.Option;
import com.wiscamp.ninechapters.problems.domain.models.problems.questions.Question;
import cube.common.core.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collection;

@Component
public class ProblemAssemblyLoader {
    public static Collection<QuestionVO> toQuestionVOs(Collection<Question> questions) {
        if (!CollectionUtils.isEmpty(questions)) {
            return CollectionUtils.toArrayList(questions, ProblemAssembler.Instance::toQuestionVO);
        }
        return new ArrayList<>();
    }

    public static Collection<OptionVO> toOptionVOs(Collection<Option> options) {
        if (!CollectionUtils.isEmpty(options)) {
            return CollectionUtils.toArrayList(options, ProblemAssembler.Instance::toOptionVO);
        }
        return new ArrayList<>();
    }

    public static Collection<AnswerVO> toAnswerVOs(Collection<Answer> answers) {
        if (!CollectionUtils.isEmpty(answers)) {
            return CollectionUtils.toArrayList(answers, ProblemAssembler.Instance::toAnswerVO);
        }
        return new ArrayList<>();
    }

    public static StemVO toStemVO(Stem stem) {
        return ProblemAssembler.Instance.toStemVO(stem);
    }
}
